package com.five.bi.controller;


import com.five.bi.model.Tableschema;
import com.five.bi.model.request.ListTableDesRequest;
import com.five.bi.model.request.ListTableRequest;
import com.five.bi.service.DataTableService;
import com.five.bi.utils.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController()
@RequestMapping("/api/v1/table")
public class DataTableController {

    @Autowired
    DataTableService dataTableService;

    @PostMapping("/list")
    public JsonData list(@RequestBody ListTableRequest listTableRequest)  {
        List<Map<String, String>> data = dataTableService.list(listTableRequest);
        if (null == data  || data.size()==0)
            return JsonData.buildError("error");
        return JsonData.buildSuccess(data);
    }

    @PostMapping("/schema")
    public JsonData schema(@RequestBody ListTableDesRequest listTableDesRequest){
        ArrayList<Tableschema> data = dataTableService.schemalist(listTableDesRequest);
        if (null == data  || data.size()==0)
            return JsonData.buildError("error");
        return JsonData.buildSuccess(data);
    }
}
